package com.training.java.core.collections.car.post15;

/**
 * Purpose of this demo  is to observe the map collection, Print all key's values.
 * There are  2 ways to print all keys and corresponding values.
 * 
 * @param args
 */

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapKeySetDemo {

	public static void main(String[] args) {
		Map<String, String> directory = new HashMap<String, String>();

		directory.put("Satya", "972 506 7885");
		directory.put("Satish", "469 371 2366");
		directory.put("Vijaya", "972 869 0042");
		directory.put("Rupa", "972 550 0208");
		directory.put("Rupa", "972 550 0208");// duplicate entry

		// Print Rupa key's values
		System.out
				.println("************************************************* ");

		System.out.println("What is Rupa's Phone number ?:  "
				+ directory.get("Rupa"));

		System.out
				.println("************************************************* ");
		/*
		 * There are 2 ways to print all keys and values. One way:Get all keys
		 * first and ask everyone's value. Using Set,KeySet-- which gives set of
		 * keys. Using for each loop to print the Key and Values. Another way is
		 * Entry Set.
		 */

		Set<String> keys = directory.keySet();// Taking Set of key in to
												// variable Keys.

		for (String eachKey : keys) {

			String value = directory.get(eachKey);// Declaring "value" variable
													// to store the value of
													// get(eachKey)
			System.out.println("Keys = " + eachKey + " Value= " + value);

		}

		System.out
				.println("************************************************* ");

	}
}
